﻿Imports IntoNails.Models
Imports IntoNails.DataAccess

Namespace ViewModel
    Public Class UserViewModel
        Inherits WorkspaceViewModel

#Region "Fields"
        Private ReadOnly _bindingUser As User
        Private ReadOnly _repository As UserRepository
#End Region

#Region "Constructors"

        Public Sub New(user As User, ByVal repository As UserRepository)
            _bindingUser = user
            _repository = repository
        End Sub

#End Region

#Region "User Properties"

        Public Property Username() As String
            Get
                Return _bindingUser.Username
            End Get
            Set(ByVal value As String)
                _bindingUser.Username = value
                Me.OnPropertyChanged("Username")
            End Set
        End Property

        Public ReadOnly Property Password() As String
            Get
                Return _bindingUser.Password
            End Get
        End Property

        Public Property DateChanged() As Date
            Get
                Return _bindingUser.DateChanged
            End Get
            Set(ByVal value As Date)
                _bindingUser.DateChanged = value
                OnPropertyChanged("DateChanged")
            End Set
        End Property

        Public ReadOnly Property EmployeeCode() As Integer
            Get
                Return _bindingUser.EmployeeCode
            End Get
        End Property

        Public Property AuthorityCode() As Integer
            Get
                Return _bindingUser.AuthorityCode
            End Get
            Set(ByVal value As Integer)
                _bindingUser.AuthorityCode = value
                OnPropertyChanged("AuthorityCode")
            End Set
        End Property

#End Region

#Region "Commands"

        Private _saveCommand As ICommand
        Public ReadOnly Property SaveCommand() As ICommand
            Get
                If _saveCommand Is Nothing Then
                    _saveCommand = New SimpleCommand(AddressOf Me.Save, AddressOf Me.CanSave)
                End If
                Return _saveCommand
            End Get
        End Property

#End Region

#Region "Methods"

        Private Sub Save()
            _repository.Save()
        End Sub

        Private Function CanSave() As Boolean
            Return _bindingUser IsNot Nothing AndAlso _repository IsNot Nothing
        End Function

#End Region

    End Class
End Namespace
